package com.atguigu.algorithm;

public class MoreThanHalfNumber {
    public static void main(String[] args) {
        int[] pub=new int[]{1,2,3,2,2,2,5,4,2};
        System.out.println(findTheNumberMoreThanHalf(pub));
    }
    public static int findTheNumberMoreThanHalf(int[]  numbers){
        if(numbers.length<2){
            return numbers[0];
        }
        int tmp=numbers[0];
        int times=0;
        for(int i=0;i<numbers.length;i++){
                if(tmp==numbers[i]){
                    times++;
                }else{
                    times--;
                    if(times==0){
                        tmp=numbers[i];
                        times=1;
                    }
                }
        }
        return tmp;
    }
}
